﻿using BenCaoXuan.Infrastructure.Attr;
using BenCaoXuan.Infrastructure.Dto;
using BenCaoXuan.Infrastructure.Dto.Admin.promotion;
using BenCaoXuan.Service.Interface.admin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BenCaoXuan.Api.Admin.Controllers.admin
{
    [ApiGroup("Admin(管理端模块)")]
    public class PromotionController : BaseController
    {
        private readonly I_Promotion_Service _promotion_Service;

        public PromotionController(I_Login_Service login_Service,I_Promotion_Service promotion_Service) : base(login_Service)
        {
            _promotion_Service = promotion_Service;
        }

        /// <summary>
        /// 管理端-通过规则类型获取对应的产品
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_ProductByRulesType(int? value) {
            var result = await _promotion_Service.Get_ProductByRulesType(value);
            return Ok(result);
        }


        /// <summary>
        /// 管理端-新增佣金规则
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Rules(AddRules_Dto dto) {
            var result = await _promotion_Service.Add_Rules(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取佣金规则
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Rules() {
            var result = await _promotion_Service.Get_Rules();
            return Ok(result);
        }

        /// <summary>
        /// 管理端-编辑佣金规则
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_Rules(UpdateRules_Dto dto) {
            var result = await _promotion_Service.Update_Rules(dto);
                return Ok(result);
        }

        /// <summary>
        /// 管理端-获取推广信息
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Commission(int page=1,int limit=5,string? key="") {
            var result = await _promotion_Service.Get_Commission(new Fenye_Dto() { 
            page=page,
            limit=limit,
            key=key??""
            });
            return Ok(result);
        }

        /// <summary>
        /// 管理端-发放佣金
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Grant_Commission(IsBan_Dto dto) {
            var employee = this.Get_AdminUser();
            if (employee == null)
            {
                return Unauthorized();
            }


            var result = await _promotion_Service.Grant_Commission(dto.id,employee.id);
            return Ok(result);
        }
    }
}
